package page.transport;

import java.util.List;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.ListDataProvider;

import app.WebApp;
import dao.RouteDao;
import entity.Route;
import entity.Transport;
import utils.Utils;
public class Ways extends WebPage {

	public Ways() {
		super();

		final RouteDao dao = new RouteDao(WebApp.DATA_XML_FOLDER);

		final List<Route> allRoute = dao.getAll();

		add(new DataView<Route>("table-rows", new ListDataProvider<Route>(allRoute)) {
			@Override
			protected void populateItem(final Item<Route> item) {
				final Route route = item.getModelObject();
				item.add(new Label("start", route.getStart()));
				item.add(new Label("end", route.getEnd()));
				item.add(new Label("autobus",Utils.getAllAutobusByRoute(route)));
				item.add(new Label("trolleybus",Utils.getAllTrolleybusByRoute(route)));
				item.add(new Label("trum",Utils.getAllTrumByRoute(route)));
			}});

		add(new Link("editTrans") {
			@Override
			public void onClick() {
				setResponsePage(new TransportListPage());
			}
		});
		add(new Link("editRoute") {
			@Override
			public void onClick() {
				setResponsePage(new RouteListPage());
			}
		});
	}
}
